{include file="public/header296" /}
<div class="layui-form" style="padding-top: 10px;">
  <div class="layui-form-item">
    <label class="layui-form-label">所属分类</label>
    <div class="layui-input-inline">
      <select name="category_id" lay-verify="required">
        <option value="">请选择分类</option>
        {volist name="category_list" id="category"}
          <option value="{$category.id}" {eq name="$item.category_id" value="$category.id"}selected {/eq}>{$category.name}</option>
        {/volist}
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-inline">
      <input type="text" name="name" value="{$item.name}" placeholder="请输入标题" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-upload" id="upload-thumb">
    <label class="layui-form-label">Banner</label>
    <button type="button" class="layui-btn" id="Lay-app-form-picture">上传图片</button><div class="layui-inline layui-word-aux">首页banner大小为750x320，工程师大小580x300</div>
    <div class="layui-upload-list">
      <label class="layui-form-label"></label>
      <img class="layui-upload-img" id="test-upload-normal-img" {notempty name="$item.image_url"}src="{$item.image_url}"{/notempty}>
    </div>
    <label class="layui-form-label"></label>
    <p id="test-upload-demoText" style="margin-bottom:5px; "></p>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">图片地址</label>
    <div class="layui-input-block">
      <input type="text" name="image_url" id="image_url" value="{$item.image_url}" style="width: 90%" placeholder="外部图片地址url" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">跳转页面</label>
    <div class="layui-input-block">
      <input type="text" name="link_url" value="{$item.link_url}" style="width: 90%" placeholder="没有跳转页面请留空" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="1" title="显示"  {eq name="item.status" value="1"}checked {/eq} />
      <input type="radio" name="status" value="-1" title="隐藏" {eq name="item.status" value="-1"}checked {/eq} />
    </div>
  </div>
  <div class="layui-form-item layui-hide">
    <input type="hidden" name="id" id="id" value="{$item.id}">
    <input type="button" lay-submit lay-filter="Lay-app-form-edit" id="Lay-app-form-edit" value="编辑">
  </div>
</div>
<script>
  layui.use(['layer', 'form', 'upload'], function(){
    var $ = layui.$
            ,upload = layui.upload
            ,form = layui.form;
    let id = '{$item.id}';
    let image_url = '{$item.image_url}';
    var uploadInst = upload.render({
      elem: '#Lay-app-form-picture'
      ,url: "{:url('uploadFile/UploadPicture')}"
      , data: {id:id,image_url:image_url}
      , before: function(obj){
        obj.preview(function(index, file, result){
          $('#test-upload-normal-img').attr('src', result);
        });
      }
      ,done: function(res){
        if(res.code == 0) {
          layer.msg(res.msg);
          $('#image_url').val(res.data.thumb_path);
        }else{
          layer.msg(res.data);
        }
      }
      ,error: function(){
        var demoText = $('#test-upload-demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
    });
  })
</script>
{include file="public/footer" /}